package com.junmeng.demo.libtopview

import android.app.Activity
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.junmeng.demo.libtopview.databinding.SimpleViewFactoryFloatingBinding
import com.junmeng.lib.ui.topview.core.IViewFactory

/**
 * 实现类似对话框效果
 */
class SimpleFloatingViewFactory : IViewFactory {
    companion object {
        const val TAG = "FloatingViewFactory"
        const val VIEW_TYPE_SIMPLE_FLOATING = "view_type_simple_floating"
    }

    private lateinit var mBinding: SimpleViewFactoryFloatingBinding

    override fun getType(): String {
        return VIEW_TYPE_SIMPLE_FLOATING
    }

    override fun onCreateView(parent: ViewGroup, inflater: LayoutInflater): View {
        Log.i(TAG, "onCreateView")
        mBinding = SimpleViewFactoryFloatingBinding.inflate(inflater, parent, false)
        return mBinding.root
    }

    override fun onAddIntoContainerView(parent: ViewGroup, child: View) {
        Log.i(TAG, "onAddIntoContainerView")
        super.onAddIntoContainerView(parent, child)
    }

    override fun onRemoveFromContainerView(parent: ViewGroup, child: View) {
        Log.i(TAG, "onRemoveFromContainerView")
        super.onRemoveFromContainerView(parent, child)
    }

    override fun onDestroyView() {
        Log.i(TAG, "onDestroyView")
        super.onDestroyView()
    }

    override fun askIfAppliedOnTargetActivity(target: Activity): Boolean {
        Log.i(TAG, "askIfAppliedOnTargetActivity")
        return target.javaClass.canonicalName != "com.junmeng.demo.libtopview.DialogActivity"
    }
}